package member.action;

import static common.utils.Constants.LIMIT;
import hotel.service.IHotelPicService;
import hotel.service.IHotelReviewService;
import hotel.service.IHotelService;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import common.action.BaseAction;
import common.pojo.HotelPic;
import common.pojo.HotelView;
import common.pojo.Review;
import common.pojo.RoomStyle;
import common.utils.Page;
import common.utils.PageUtil;
import common.utils.PaginationUtil;

@SuppressWarnings("serial")
@Scope("prototype")
@Controller("index")
public class IndexAction extends BaseAction {

	public String index() throws Exception {
		SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd 14:00:00");
		SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd 12:00:00");
		//系统当前日期的1天后
		String checkinTime=df1.format(System.currentTimeMillis()+(long)1 * 24 * 60 * 60 * 1000);
		//当前日期的2天后
		String checkoutTime=df2.format(System.currentTimeMillis()+(long)2 * 24 * 60 * 60 * 1000);
		String currentTmp = request.getParameter("current");
		int current;
		if(currentTmp==null) current =1;
		else current = Integer.valueOf(request.getParameter("current"));
		//默认获取最近两天房间剩余量
		roomlist = hotelService.findRoomList("isDelete=0",Timestamp.valueOf(checkinTime),Timestamp.valueOf(checkoutTime));
		hotel = hotelService.findHotel();
		Page page = PageUtil.createPage(LIMIT, reviewService.getCount(" where status=1"), current);
		review = reviewService.findList(" status=1", page.getBeginIndex(),LIMIT,"id desc");	
		pagination = PaginationUtil.getPaginationStyle(page,"index.action");
		return "index";
	}
	public String getRoomLeft() throws Exception {
		   checkinTime=request.getParameter("checkinTime");
		   checkoutTime=request.getParameter("checkoutTime");
		//入住时间
		  Timestamp startTime=Timestamp.valueOf(checkinTime+" 14:00:00");
		//退房时间
		Timestamp endTime=Timestamp.valueOf(checkoutTime+" 12:00:00");
		roomlist = hotelService.findRoomList("isDelete=0",startTime,endTime);
		hotel = hotelService.findHotel();
		Page page = PageUtil.createPage(LIMIT, reviewService.getCount(" where status=1"), 1);
		review = reviewService.findList("status=1", page.getBeginIndex(),LIMIT,"id desc");	
		pagination = PaginationUtil.getPaginationStyle(page,"index.action");
		return "index";
	}
	public String welcome(){
		hotel = hotelService.findHotel();
		hotelPicList=hotelPicService.find();
		return "welcome";
	}
	@Resource
	private IHotelService hotelService;
	@Resource
	private IHotelPicService hotelPicService;
	@Resource
	private IHotelReviewService reviewService;
	private List<HotelPic> hotelPicList;
	private List<RoomStyle> roomlist;
	private HotelView hotel;
	private List<Review> review;
	private String pagination;
	private String checkinTime;
	private String checkoutTime;

	public String getCheckinTime() {
		return checkinTime;
	}

	public void setCheckinTime(String checkinTime) {
		this.checkinTime = checkinTime;
	}

	public String getCheckoutTime() {
		return checkoutTime;
	}

	public void setCheckoutTime(String checkoutTime) {
		this.checkoutTime = checkoutTime;
	}


	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}
	public List<HotelPic> getHotelPicList() {
		return hotelPicList;
	}

	public void setHotelPicList(List<HotelPic> hotelPicList) {
		this.hotelPicList = hotelPicList;
	}

	public List<RoomStyle> getRoomlist() {
		return roomlist;
	}

	public void setRoomlist(List<RoomStyle> roomlist) {
		this.roomlist = roomlist;
	}

	public HotelView getHotel() {
		return hotel;
	}

	public void setHotel(HotelView hotel) {
		this.hotel = hotel;
	}

	public List<Review> getReview() {
		return review;
	}

	public void setReview(List<Review> review) {
		this.review = review;
	}

}